#include "playpausebutton.h"
#include <QDebug>

PlayPauseButton::PlayPauseButton(QWidget* parent) : QPushButton(parent),
playIcon(":/images/media-playback-start.png"), 
pauseIcon(":/images/media-playback-stop.png"),
bufferingIcon(":/images/user-away-extended.png"),
showingPlay(true) {
	setFlat(true);
	setIconSize(QSize(48,48));
	setIcon(playIcon);	
	connect(this, SIGNAL(clicked(bool)), this, SLOT(onButtonClicked(bool)));
}

void PlayPauseButton::onButtonClicked(bool) {
	showingPlay = !showingPlay;
	if(!showingPlay) {
		setIcon(pauseIcon);
		emit(play());
	}
	else {
		setIcon(playIcon);
		emit(pause());
	}
}

void PlayPauseButton::onBuffering(int percent) {
	if(percent < 100)
		setIcon(bufferingIcon);
	else if(showingPlay)
		setIcon(playIcon);
	else
		setIcon(pauseIcon);
}
